<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <h3>{{infoName}}  &  图片管理</h3>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" >
        <el-button
          slot="right"
          v-permission="['admin','album:back']"

          class="filter-item"
          size="mini"
          type="primary"
          @click="back"
        >返回上一级</el-button>
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="name">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="path">
            <el-input v-model="form.path" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('name')" prop="name" label="name" />
        <el-table-column v-if="columns.visible('path')" prop="path" label="path" >
          <template slot-scope="scope"><img style="height: 80px" :src="scope.row.path"></template>
        </el-table-column>
        <el-table-column v-permission="['admin','introImg:edit','introImg:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudIntroImg from '@/api/introImg'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '北戴河图片', url: 'api/introImg', sort: 'id,desc', crudMethod: { ...crudIntroImg }})
const defaultForm = { id: null, name: null, path: null, introId: null }
export default {
  name: 'IntroImg',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      infoName:'',
      permission: {
        add: ['admin', 'introImg:add'],
        edit: ['admin', 'introImg:edit'],
        del: ['admin', 'introImg:del']
      },
      rules: {
      }    }
  },
  created() {
    this.init();
  },
  methods: {
    back(){
      this.$router.back(-1);
    },
    init(){
      this.form.introId= this.$route.query.id;
      this.infoName= this.$route.query.name;
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      //const query = this.query
      this.crud.params['introId'] = this.$route.query.id;
      return true
    },
    [CRUD.HOOK.beforeToAdd]() {
      //const query = this.query
      this.form.introId= this.$route.query.id;
      return true
    },
  }
}
</script>

<style scoped>

</style>
